package com.china08.yxyapi.repository.db;

import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.china08.yxyapi.entity.db.res.YxyResResource;

public interface YxyResResourceRepository extends JpaRepository<YxyResResource, String> {

    List<YxyResResource> findByIdIn(List<String> asList);

    YxyResResource findById(String id);

    List<YxyResResource> findByMd5OrderByUploadTimeAsc(String md5);

    List<YxyResResource> findByTypeIdAndDistrictCode(String string, String districtCode);

    List<YxyResResource> findByTypeIdAndCityCode(String string, String districtCode);

    List<YxyResResource> findByTypeIdAndProvinceCode(String string, String districtCode);

    List<YxyResResource> findByDistrictCodeAndTypeIdNot(String districtCode, String string);

    List<YxyResResource> findByCityCodeAndTypeIdNot(String districtCode, String string);

    List<YxyResResource> findByProvinceCodeAndTypeIdNot(String districtCode, String string);

    @Query(value = "select distinct uploaderId , uploaderName ,uploaderSchoolId ,uploaderSchoolName  from YxyResResource t where uploadTime>?1 and uploadTime<?2")
    List<Object[]> findByUploadTime(Date startDate, Date endDate);

    List<YxyResResource> findTop10ByConvertStatusAndConvertRetryTimesLessThan(Integer status, Integer times);

    @Query(nativeQuery = true, value = "select distinct re.school_name,re.city_code,re.district_code from yxy_res.yxy_res_resource re where re.uploader_school_id = ?1")
    List<Object[]> getSchoolValue(String key);

    @Query(nativeQuery = true, value = "select distinct re.uploader_name from yxy_res.yxy_res_resource re where re.uploader_id = ?1")
    List<Object> getUserName(String userId);

    Integer countById(String resourceId);

    @Query(nativeQuery = true, value = "select re.is_high_quality_yx ,re.is_vip from yxy_res.yxy_res_resource re where re.id = ?1")
    List<Object[]> findIsHighQualityYxAndIsVipById(String resourceId);

    Page<YxyResResource> findByTypeId(String string, Pageable pageable);
}
